﻿@{
    ViewBag.Title = "Index";
}


<div style="width: 100%;">
    <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    <a id="add" class="mini-button" iconcls="icon-add" plain="true" onclick="addRow()">增加</a>
                    <a id="delete" class="mini-button" iconcls="icon-remove" plain="true" onclick="removeRow()">删除</a>
                    <a id="edit" class="mini-button" iconcls="icon-save" plain="true" onclick="saveData()">保存</a>
                </td>
                <td style="white-space: nowrap;">
                    <input id="key" class="mini-textbox" emptytext="请输入关键字" style="width: 250px;" onenter="onKeyEnter" />
                    <a class="mini-button" plain="true" onclick="search()">查询</a>
                </td>
            </tr>
        </table>
    </div>
</div>

<div class="mini-fit" style="height: 100%;">
    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;"
        url="GetTurck" idfield="TruckID" pagesize="20"
        allowcelledit="true" allowcellselect="true" multiselect="true"
        editnextonenterkey="true" editnextrowcell="true">
        <div property="columns">
            <div type="indexcolumn"></div>
            <div type="checkcolumn"></div>
            <div field="TruckNum" width="150" headeralign="center" vtype="required">
                车牌照号<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="Brand" width="120" headeralign="center" >
                车品牌<input property="editor" class="mini-textbox" style="width: 100%;" minheight="60" />
            </div>
             <div field="Model" width="150" headeralign="center" >
                型号<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="EngineNum" width="120" headeralign="center" >
                发动机号<input property="editor" class="mini-textbox" style="width: 200px;" minheight="60" />
            </div>
             <div field="TransportNum" width="150" headeralign="center" >
                运营证号<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="InsuranceBillNum" width="150" headeralign="center" >
                保险单号<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>

             <div field="Owner" width="100" headeralign="center" >
                车主<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="OwnerTel" width="100" headeralign="center" >
                车主电话<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
             <div field="LinkMan" width="100" headeralign="center" >
                联系人<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="LinkTel" width="100" headeralign="center" >
                联系电话<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>

             <div field="IsCompany" width="100" headeralign="center" >
                是否公司车辆<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>


            <div field="MaxLong" width="100" headeralign="center" >
                长(米)<input property="editor" class="mini-textbox" style="width: 200px;" minheight="60" />
            </div>
             <div field="MaxWidth" width="100" headeralign="center" >
                宽(米)<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="MaxHeight" width="100" headeralign="center" >
                高(米)<input property="editor" class="mini-textbox" style="width: 200px;" minheight="60" />
            </div>

             <div field="MaxLoadWeight" width="100" headeralign="center" >
                最大载重(吨)<input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="MaxLoadVolume" width="100" headeralign="center" >
                最大体积(立方)<input property="editor" class="mini-textbox" style="width: 200px;" minheight="60" />
            </div>
            <div field="ContractNum" width="120" headeralign="center">
                合同号<input property="editor" class="mini-textbox" style="width: 200px;" minheight="60" />
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    mini.parse();

    var grid = mini.get("datagrid1");
    grid.load({
        fail: function () {
        }
    });

    function search() {
        var key = mini.get("key").getValue();

        grid.load({
            key: key, fail: function () {
            }
        });
    }

    function onKeyEnter(e) {
        search();
    }

    function addRow() {
        var newRow = { name: "New Row" };
        grid.addRow(newRow, 0);
        grid.beginEditCell(newRow, "DKey");
    }

    function removeRow() {
        var rows = grid.getSelecteds();
        if (rows.length > 0) {
            grid.removeRows(rows, true);
        }
    }

    function saveData() {

        grid.validate();
        if (grid.isValid() == false) {
            var error = grid.getCellErrors()[0];
            grid.beginEditCell(error.record, error.column);
            return;
        }

        var added = grid.getChanges("added");
        var jsonAdd = mini.encode(added);

        var modified = grid.getChanges("modified");
        var jsonEdit = mini.encode(modified);

        var removed = grid.getChanges("removed");
        var jsonDel = mini.encode(removed);

        grid.loading("保存中，请稍后......");
        $.ajax({
            url: "Save",
            data: { add: jsonAdd, edit: jsonEdit, del: jsonDel },
            type: "post",
            success: function (text, flag, res) {
                grid.unmask();
                if (res.responseText == "") {
                    grid.reload();
                }
                else
                    top.mini.alert(res.responseText);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                mini.alert(errorThrown.responseText);
            }
        });
    }

</script>

